function y = FindMDCPeak(x)

global mdc 

A1=x(1);%amplitude of peak 1
m1=x(2);%mean of peak 1
g1=x(3);%gamma of peak 1
A2=x(4);%Gaussian peak 2 
m2=x(5);
g2=x(6);


k=linspace(1,length(mdc),length(mdc));
k=k-mean(k);
k=k/max(k)*0.788;

range=mdc*0+1;
for i=1:length(mdc)
    if mdc(i)<max(mdc)*0.02;
        range(i)=0;
    end
    if k(i)<0.09;
        range(i)=0;
    end
end
range=logical(range);


L1=A1*(g1^2./((k-m1).^2+g1^2))/(pi*g1);
L2=A2*(g2^2./((k-m2).^2+g2^2))/(pi*g2);
L=L1+L2;
L=(L+fliplr(L));
LL=L(range);
MM=mdc(range);

if size(MM)~=size(LL)
    MM=MM';
end

y=sum(abs(LL-MM).^2);

end

